//
//  LKDayInforPersonInforEditViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/4/23.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKDayInforPersonInforEditViewController.h"
#import "LKDayInforEditHeaderView.h"
#import "LKDayInforPersonEditCell.h"
#import "LKDayInforPersonEditSpecialCell.h"
#import "GFAddressPicker.h"
#import "LKUpdatePersomInforModel.h"
#import "YLPushViewModel.h"
@interface LKDayInforPersonInforEditViewController ()<UITableViewDelegate,UITableViewDataSource,UIImagePickerControllerDelegate,UIViewControllerTransitioningDelegate,GFAddressPickerDelegate,UINavigationControllerDelegate>
@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)NSArray *titlesArray;
@property (nonatomic, strong) GFAddressPicker *pickerView;
@property(nonatomic,assign)CGFloat textCellHeight;
@property(nonatomic,strong)LKUpdatePersomInforModel *submitInforModel;
@property(nonatomic,strong)NSArray *contentsArray;
@property(nonatomic,strong)NSString *HeadPortrait;
@property(nonatomic,assign)BOOL isHeader;
@property(nonatomic,strong)UIImage *currentEerweimaImage;
@end

@implementation LKDayInforPersonInforEditViewController

//-(LKBaseTableview *)tableview{
//    if (!_tableview) {
//        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped registercellClasss:@[@"LKDayInforPersonEditCell",@"LKDayInforPersonEditSpecialCell"]];
//        [self.view addSubview:_tableview];
//        _tableview.delegate = self;
//        _tableview.dataSource = self;
//        _tableview.separatorStyle = UITableViewCellSelectionStyleGray;
//    }
//    return _tableview;
//}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBarTintColor:COLOR_HEX(0x497be9)];
    //设置导航条文字颜色 白色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.delegate = self;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    //设置导航条文字颜色 白色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:COLOR_HEX(0x000000)}];
}

/**
 设置tableview的页面
 */
-(void)setTableViewUI{
    self.tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped registercellClasss:@[@"LKDayInforPersonEditCell",@"LKDayInforPersonEditSpecialCell"]];
    [self.view addSubview:self.tableview];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    self.tableview.separatorStyle = UITableViewCellSelectionStyleGray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTableViewUI];
    _submitInforModel = [[LKUpdatePersomInforModel alloc] init];
    LKUserInfor *model = [LKUserInforTool account];
    self.submitInforModel.UserSerialNumber = model.userSerialNumber;
    self.textCellHeight = 180;
    _submitInforModel.name = model.name;
    _submitInforModel.surname = model.surname;
    _submitInforModel.PostId = model.postId;
    _submitInforModel.DepartmentId = model.departmentId;
    _submitInforModel.Tel = model.tel;
    _submitInforModel.city = model.city;
    _submitInforModel.PersonalProfile = model.personalProfile;
    _submitInforModel.HeadPortrait = model.headPortrait;
    _submitInforModel.ErWeiMa = model.erWeiMa;
    _submitInforModel.Postname = model.postName;
    _submitInforModel.CorporateName = model.corporateName;
    _submitInforModel.PersonalProfile = model.personalProfile;
    //data:图片的二进制数据
    [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_submitInforModel.ErWeiMa]]  options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {

    } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {

        self.currentEerweimaImage = image;
        self.textCellHeight = 180;
        [self.tableview reloadData];
    }];
    // Do any additional setup after loading the view.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"编辑个人资料";
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"保存" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(savePersoninformation) forControlEvents:UIControlEventTouchUpInside];
    [self.backButton setImage:[UIImage imageNamed:@"back2"] forState:UIControlStateNormal];
    [self.backButton setTitle:@" 返回" forState:UIControlStateNormal];
    [self.backButton setTitleColor:[UIColor whiteColor]];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titlesArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WS(weakSelf)
    LKDayInforPersonEditCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKDayInforPersonEditCell"];
    LKDayInforPersonEditSpecialCell *spectCell = [tableView dequeueReusableCellWithIdentifier:@"LKDayInforPersonEditSpecialCell"];
    spectCell.titiLabel.text = self.titlesArray[indexPath.row];
    spectCell.bgview.layer.borderColor = COLOR_HEX(0xDCDBDC).CGColor;
    spectCell.bgview.layer.borderWidth = 1;
        if (indexPath.row == self.titlesArray.count - 1) {
            spectCell.textView.hidden = YES;
            if (self.submitInforModel.ErWeiMa) {
                [spectCell.erweimaBtn setTitle:@"" forState:UIControlStateNormal];
                [spectCell.erweimaBtn setImage:self.currentEerweimaImage forState:UIControlStateNormal];
            }else{
                
            }
            [[spectCell.erweimaBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
                //             判断是否支持相机
//                if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//                    [SVProgressHUD showInfoWithStatus:@"无法使用相机"];
//                    return;
//                }
                LKDayInforPersonEditSpecialCell *cell = [_tableview cellForRowAtIndexPath:indexPath];
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                
                if (self.submitInforModel.ErWeiMa) {
                    dispatch_queue_t gloabeQueue = dispatch_queue_create(0, 0);
                    dispatch_async(gloabeQueue, ^{
//                        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,self.submitInforModel.ErWeiMa]]];
//                        UIImage *image = [UIImage imageWithData:data];
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [cell.erweimaBtn setImage:self.currentEerweimaImage forState:UIControlStateNormal];
                            [alert addAction:[UIAlertAction actionWithTitle:@"删除二维码" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                UIAlertController *aler = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认删除二维码" preferredStyle:UIAlertControllerStyleAlert];
                                [aler addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                                    
                                }]];
                                [aler addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                    weakSelf.submitInforModel.ErWeiMa = nil;
                                    [cell.erweimaBtn setTitle:@"  上传个人二维码" forState:UIControlStateNormal];
                                    [cell.erweimaBtn setImage:[UIImage imageNamed:@"erweimasuolve"] forState:UIControlStateNormal];
                                }]];
                                [self presentViewController:aler animated:YES completion:nil];
                                
                            }]];
                            [alert addAction:[UIAlertAction actionWithTitle:@"更换二维码" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                UIAlertController *alerts = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
                                NSUInteger sourceTypes = UIImagePickerControllerSourceTypePhotoLibrary;
                                [self camerOrAlbumsPhotoChooseWithAlert:alerts AndSourceType:sourceTypes];
                                [self presentViewController:alerts animated:YES completion:nil];
                            }]];
                            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                            }]];
                            [self presentViewController:alert animated:YES completion:nil];
                        });
                    });
                }else{
                    
                    [cell.erweimaBtn setImage:[UIImage imageNamed:@"erweimasuolve"] forState:UIControlStateNormal];
                    [self camerOrAlbumsPhotoChooseWithAlert:alert AndSourceType:sourceType];
                    
                    [self presentViewController:alert animated:YES completion:nil];
                }
            }];
            return spectCell;
        }
    if (indexPath.row == self.titlesArray.count - 2) {

        WS(weakSelf)
        spectCell.textView.text = self.submitInforModel.PersonalProfile == nil  ? @"输入":self.submitInforModel.PersonalProfile;
        [[spectCell.textView rac_textSignal] subscribeNext:^(NSString * _Nullable x) {
          SS(strongSelf)
            strongSelf.submitInforModel.PersonalProfile = x;
            NSLog(@"%@",x);
        }];
        return spectCell;
    }
    cell.titleLabel.text = self.titlesArray[indexPath.row];
    switch (indexPath.row) {
        case 0:
        {
            cell.contentLabel.text = self.submitInforModel.name;
        }
            break;
        case 1:
        {
            cell.contentLabel.text = self.submitInforModel.surname;
        }
            break;
        case 2:
        {
            cell.contentLabel.text = self.submitInforModel.UserSerialNumber;
        }
            break;
        case 3:
        {
            cell.contentLabel.text = self.submitInforModel.Postname;
        }
            break;
        case 4:
        {
            cell.contentLabel.text = self.submitInforModel.CorporateName;
        }
            break;
        case 5:
        {
            cell.contentLabel.text = self.submitInforModel.Tel;
        }
            break;
        case 6:
        {
            cell.contentLabel.text = self.submitInforModel.city;
        }
            break;
            
        default:
            break;
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == self.titlesArray.count - 2) {
        return self.textCellHeight;
    }
    if (indexPath.row == self.titlesArray.count - 1) {
        return 206;
    }
    return 50;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    LKDayInforEditHeaderView *headerView = [[[NSBundle mainBundle] loadNibNamed:@"LKDayInforEditHeaderView" owner:nil options:nil] lastObject];
    headerView.iconImageView.userInteractionEnabled = YES;
    headerView.iconImageView.layer.cornerRadius = 32.5;
    headerView.iconImageView.layer.masksToBounds = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chooseImagePicker:)];
    [headerView.iconImageView addGestureRecognizer:tap];
    [headerView.iconImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,self.submitInforModel.HeadPortrait]] placeholderImage:[UIImage imageNamed:@"minecardtouxiang"]];
    return headerView;
}
-(void)chooseImagePicker:(UITapGestureRecognizer *)tap{
    self.isHeader = YES;
    //             判断是否支持相机
//    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//        [SVProgressHUD showInfoWithStatus:@"无法使用相机"];
//        return;
//    }
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self camerOrAlbumsPhotoChooseWithAlert:alert AndSourceType:sourceType];
    [self presentViewController:alert animated:YES completion:nil];
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 200.0f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.00000000001f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            [SVProgressHUD showInfoWithStatus:@"员工姓名不可更改"];
        }
            break;
        case 1:
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入" message:@"" preferredStyle:UIAlertControllerStyleAlert];
            [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
                
            }];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                UITextField *contentTf = alert.textFields.firstObject;
                LKDayInforPersonEditCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                cell.contentLabel.text = contentTf.text;
                self.submitInforModel.surname = contentTf.text;
            }]];
            [self presentViewController:alert animated:YES completion:nil];
        }
            break;
        case 2:
        {
            [SVProgressHUD showInfoWithStatus:@"员工编号不可更改"];

        }
            break;
        case 3:
        {
            [SVProgressHUD showInfoWithStatus:@"员工职务不可更改"];
//            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入" message:@"" preferredStyle:UIAlertControllerStyleAlert];
//            [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
//                
//            }];
//            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//                
//            }]];
//            [alert addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                UITextField *contentTf = alert.textFields.firstObject;
//                LKDayInforPersonEditCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//                cell.contentLabel.text = contentTf.text;
//                self.submitInforModel.positon = contentTf.text;
//            }]];
//            [self presentViewController:alert animated:YES completion:nil];
        }
            break;
        case 4:
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入" message:@"" preferredStyle:UIAlertControllerStyleAlert];
            [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
                
            }];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                UITextField *contentTf = alert.textFields.firstObject;
                LKDayInforPersonEditCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                cell.contentLabel.text = contentTf.text;
                self.submitInforModel.CorporateName = contentTf.text;
            }]];
            [self presentViewController:alert animated:YES completion:nil];
        }
            break;
            case 5:
        {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入" message:@"" preferredStyle:UIAlertControllerStyleAlert];
            [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
                
            }];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                UITextField *contentTf = alert.textFields.firstObject;
                LKDayInforPersonEditCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                cell.contentLabel.text = contentTf.text;
              self.submitInforModel.Tel = contentTf.text;
            }]];
            [self presentViewController:alert animated:YES completion:nil];
        }
            break;
        case 6:
            
        {
            if (!_pickerView) {
                _pickerView = [[GFAddressPicker alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
                [_pickerView updateAddressAtProvince:@"上海市" city:@"上海市" town:@"浦东新区"];
                _pickerView.delegate = self;
                _pickerView.font = [UIFont boldSystemFontOfSize:18];
            }
            [self.view addSubview:self.pickerView];
            [self.view bringSubviewToFront:self.pickerView];

        }
            break;
        case 7:
        {
            
        }
            break;
        case 8:
        {
        }
            break;
        default:
            break;
    }


}

/**
 从相册或者相机中选择图片

 @param alert 弹框
 @param sourceTypea 相机或者相册
 */
-(void)camerOrAlbumsPhotoChooseWithAlert:(UIAlertController *)alert AndSourceType:(NSInteger) sourceTypea{
    __block NSInteger sourceType = sourceTypea;
    
    [alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //来源:相机
        sourceType = UIImagePickerControllerSourceTypeCamera;
        // 跳转到相机或相册页面
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = (id)self;
        imagePickerController.allowsEditing = NO;
        imagePickerController.sourceType = sourceType;
        imagePickerController.transitioningDelegate = self;
        imagePickerController.modalPresentationStyle = UIModalPresentationCustom;
        [self presentViewController:imagePickerController animated:YES completion:nil];
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"从相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //来源:相册
        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        // 跳转到相机或相册页面
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = (id)self;
        imagePickerController.allowsEditing = NO;
        imagePickerController.navigationBar.translucent = NO;
        [imagePickerController.navigationBar setBarTintColor:blueDefault];
        imagePickerController.sourceType = sourceType;
        imagePickerController.transitioningDelegate = self;
        imagePickerController.modalPresentationStyle = UIModalPresentationCustom;
        [self presentViewController:imagePickerController animated:YES completion:nil];
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
}
#pragma mark - 调用相机的代理方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    LKDayInforPersonEditSpecialCell *cell = [_tableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:8 inSection:0]];
    UIImage *aimage = image;
    if (self.isHeader) {
        self.isHeader = NO;
        LKDayInforEditHeaderView *headerView = [[[NSBundle mainBundle] loadNibNamed:@"LKDayInforEditHeaderView" owner:nil options:nil] lastObject];
        headerView.iconImageView.image = aimage;
        [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:otherOfPictureUrl parameters:nil imageArray:@[aimage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            self.submitInforModel.HeadPortrait = responseObject[@"fileUrl"];
            [self.tableview reloadData];
        } failure:^(NSString * _Nullable error) {
            
        }];
    }else{
        [cell.erweimaBtn setImage:aimage forState:UIControlStateNormal];
        [cell.erweimaBtn setTitle:nil forState:UIControlStateNormal];
        cell.erweimaBtn.titleLabel.text = nil;
        [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:otherOfPictureUrl parameters:nil imageArray:@[aimage] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            
            self.submitInforModel.ErWeiMa = responseObject[@"fileUrl"];
            
//            [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_submitInforModel.ErWeiMa]]  options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
//
//            } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
//                self.currentEerweimaImage = image;
//                [self.tableview reloadData];
//            }];
            
//            NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,self.submitInforModel.ErWeiMa]]];
//            self.currentEerweimaImage = [UIImage imageWithData:data];
            
            [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_submitInforModel.ErWeiMa]]  options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
                
            } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
                
                self.currentEerweimaImage = image;
                self.textCellHeight = 180;
                [self.tableview reloadData];
            }];
        } failure:^(NSString * _Nullable error) {
            
        }];
    }

}
//缩放图片到指定大小的imageview
- (UIImage*)imageCompressWithSimple:(UIImage*)image scaledToSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0,0,size.width,size.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
#pragma mark -地址选择器的代理方法
- (void)GFAddressPickerCancleAction
{
    [self.pickerView removeFromSuperview];
}

- (void)GFAddressPickerWithProvince:(NSString *)province
                               city:(NSString *)city area:(NSString *)area
{
    [self.pickerView removeFromSuperview];
    LKDayInforPersonEditCell *cell = [self.tableview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:6 inSection:0]];
    cell.contentLabel.text = [NSString stringWithFormat:@"%@/%@/%@",province,city,area];
    self.submitInforModel.city = cell.contentLabel.text;
}
#pragma mark 导航栏的代理方法
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blueColor];
}
-(NSArray *)titlesArray{
    if (!_titlesArray) {
        _titlesArray = @[@"员工姓名:",@"员工昵称:",@"员工编号:",@"职务:",@"公司名称:",@"联系方式:",@"所在城市:",@"个人简介:",@"微信二维码:"];
    }
    return _titlesArray;
}
/** 获取文字CGSize */
- (CGSize)getSizeWithString:(NSString *)string Font:(UIFont *)font maxSize:(CGSize)maxSize{
    
    return [string boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil].size;
}

/**
 保存用户个人信息并提交
 */
-(void)savePersoninformation{
    
    NSDictionary *param0 = [NSDictionary dictionaryWithObjectsAndKeys:self.HeadPortrait,@"HeadPortrait", nil];
    NSDictionary *param1 = [NSDictionary dictionaryWithObjectsAndKeys:[LKUserInforTool account].workerId,@"Id", nil];
    NSDictionary *param = [self.submitInforModel properties_aps];
    NSMutableDictionary *mutableDic = [[NSMutableDictionary alloc] init];
    [mutableDic addEntriesFromDictionary:param];
    [mutableDic addEntriesFromDictionary:param0];
    [mutableDic addEntriesFromDictionary:param1];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:editUserUrl header:[LKUserInforTool header] parameters:mutableDic progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD showInfoWithStatus:@"保存成功"];
        
        [self reloadUserInforamtion];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
-(void)reloadUserInforamtion{
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:UserDetailUrl header:[LKUserInforTool header] parameters:nil progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        LKUserInfor *userInfor = [LKUserInfor accountWithDict:responseObject[@"result"]];
        userInfor.token = [LKUserInforTool account].token;
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:userAccountCaculationUrl header:[LKUserInforTool header] parameters:nil progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            NSString *customerCout = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"cusertomerCount"]];
            NSString *investMoney = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"orderInverstment"]];
            NSString *investFundMoney = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"orderInverstmentFund"]];
            userInfor.cusertomerCount = customerCout;
            userInfor.orderInverstment = investMoney;
            userInfor.orderInverstmentFund = investFundMoney;
            [LKUserInforTool saveAccount:userInfor];
            [YLPushViewModel setUpMyPushInfo];
            [self.navigationController popViewControllerAnimated:YES];
        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
        
        
    } failure:^(NSString * _Nullable errorMessage) {
    }];

}
/**
 更新用户详情
 */
//-(void)getAccountDetailInformation{
//    [self getAccountDetailInformation];
////    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:UserDetailUrl header:[LKUserInforTool header] parameters:nil progress:^(NSProgress * _Nullable progress) {
////
////    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
////        LKUserInfor *userInfor = [LKUserInfor accountWithDict:responseObject[@"result"]];
////        userInfor.token = [LKUserInforTool account].token;
////        [LKUserInforTool saveAccount:userInfor];
////        [[NSNotificationCenter defaultCenter] postNotificationName:reloadUserInformationNotice object:nil];
////    } failure:^(NSString * _Nullable errorMessage) {
////    }];
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//-(LKUpdatePersomInforModel *)submitInforModel{
//    if (!_submitInforModel) {
//        _submitInforModel = [[LKUpdatePersomInforModel alloc] init];
//        LKUserInfor *model = [LKUserInforTool account];
//        _submitInforModel.UserSerialNumber = model.userSerialNumber;
//        _submitInforModel.name = model.name;
//        _submitInforModel.PostId = model.postId;
//        _submitInforModel.DepartmentId = model.departmentId;
//        _submitInforModel.Tel = model.tel;
//        _submitInforModel.city = model.city;
//        _submitInforModel.PersonalProfile = model.personalProfile;
//        _submitInforModel.HeadPortrait = model.headPortrait;
//        _submitInforModel.ErWeiMa = model.erWeiMa;
//        //data:图片的二进制数据
////        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_submitInforModel.ErWeiMa]]  options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
////
////        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
////            self.currentEerweimaImage = image;
////        }];
//
//        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_submitInforModel.ErWeiMa]]];
//        self.currentEerweimaImage = [UIImage imageWithData:data];
//        _submitInforModel.Postname = model.postName;
//        _submitInforModel.CorporateName = model.corporateName;
//        _submitInforModel.PersonalProfile = model.personalProfile;
//    }
//    return _submitInforModel;
//}




//-(NSArray *)contentsArray{
//    if (!_contentsArray) {
//        _contentsArray = @[
//        self.submitInforModel.name,
//        self.submitInforModel.workerId,
//        _submitInforModel.PostId, _submitInforModel.DepartmentId,
//        _submitInforModel.Tel,
//        _submitInforModel.city];
//    }
//    return _contentsArray;
//}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
